home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_casm / snip9611.zip / DATE.HPP < prev    next >
C/C++ Source or Header  |  1996-11-24  |  5KB  |  157 lines

  1. // +++Date last modified: 25-Oct-1996
  2.  
  3. /*
  4.  * This file is part of PB-Lib C/C++ Library
  5.  *
  6.  * Copyright (c) 1995, 1996 Branislav L. Slantchev
  7.  * A Product of Silicon Creations, Inc.
  8.  *
  9.  * This class is hereby donated to the SNIPPETS collection (maintained
  10.  * by Bob Stout). You are granted the right to use the code contained
  11.  * herein free of charge as long as you keep this copyright notice intact.
  12.  *
  13.  * Contact: 73023.262@compuserve.com
  14. */
  15. #ifndef __DATE_INC
  16. #define __DATE_INC
  17.  
  18. typedef unsigned long ulong;
  19. typedef enum { False, True } Boolean;
  20. #include <time.h>
  21.  
  22. class zDate
  23. {
  24. public:
  25.     enum month {
  26.         jan = 1, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec
  27.     };
  28.  
  29.     enum week_day {
  30.         mon = 1, tue, wed, thu, fri, sat, sun
  31.     };
  32.  
  33.     enum moon_phase {
  34.         new_moon, waxing_crescent, first_quater, waxing_gibbous,
  35.         full_moon, waning_gibbous, third_quater, waning_crescent
  36.     };
  37.  
  38.     zDate();
  39.     zDate(month month, int day, int year);
  40.     zDate(int dayOfYear, int year);
  41.     zDate(const zDate &aDate);
  42.     zDate(ulong nDayNumber);
  43.     zDate(const struct tm *date);
  44.  
  45.     zDate             AddMonths(int nMonths) const;
  46.     zDate             AddWeeks(int nWeeks) const;
  47.     zDate             AddYears(int nYears) const;
  48.     int               Age(const zDate &aDate) const;
  49.     zDate             BeginDST() const;
  50.     static zDate      BeginDST(int aYear);
  51.     int               Day() const;
  52.     ulong             DayNumber() const;
  53.     week_day          DayOfWeek() const;
  54.     int               DayOfYear() const;
  55.     int               DaysInMonth() const;
  56.     static int        DaysInMonth(month aMonth, int aYear);
  57.     int               DaysInYear() const;
  58.     static int        DaysInYear(int year);
  59.     zDate             Easter() const;
  60.     static zDate      Easter(int year);
  61.     zDate             EndDST() const;
  62.     static zDate      EndDST(int aYear);
  63.     Boolean           IsDST() const;
  64.     static Boolean    IsDST(const zDate &date);
  65.     Boolean           IsLeapYear() const;
  66.     static Boolean    IsLeapYear(int year);
  67.     Boolean           IsValid() const;
  68.     static Boolean    IsValid(month aMonth, int aDay, int aYear);
  69.     month             Month() const;
  70.     moon_phase        MoonPhase() const;
  71.     static moon_phase MoonPhase(const zDate &date);
  72.                       operator long() const;
  73.     Boolean           operator!=(const zDate &aDate) const;
  74.     zDate             operator+(int nDays) const;
  75.     zDate             operator+(long nDays) const;
  76.     zDate             operator++();
  77.     zDate             operator++(int);
  78.     zDate&            operator+=(int nDays);
  79.     zDate&            operator+=(long nDays);
  80.     long              operator-(const zDate &aDate) const;
  81.     zDate             operator-(int nDays) const;
  82.     zDate             operator-(long nDays) const;
  83.     zDate             operator--();
  84.     zDate             operator--(int);
  85.     zDate&            operator-=(int nDays);
  86.     zDate&            operator-=(long nDays);
  87.     Boolean           operator<(const zDate &aDate) const;
  88.     Boolean           operator<=(const zDate &aDate) const;
  89.     zDate&            operator=(const zDate &aDate);
  90.     Boolean           operator==(const zDate &aDate) const;
  91.     Boolean           operator>(const zDate &aDate) const;
  92.     Boolean           operator>=(const zDate &aDate) const;
  93.     char              operator[](int index) const;
  94.     static void       SetBeginDST(month aMonth, week_day aWeekDay);
  95.     static void       SetEndDST(month aMonth, week_day aWeekDay);
  96.     static zDate      Today();
  97.     int               WeekOfMonth() const;
  98.     int               WeekOfYear() const;
  99.     int               WeeksInYear() const;
  100.     static int        WeeksInYear(int year);
  101.     int               Year() const;
  102.  
  103.     // Pope Gregor XIII's reform cancelled 10 days:
  104.     // the day after Oct 4 1582 was Oct 15 1582
  105.     static const int      ReformYear;
  106.     static const month    ReformMonth;
  107.     static const ulong    ReformDayNumber;
  108.  
  109. protected:
  110.     // Daylight Savings Time Month and Day of Week
  111.     static month    BeginDSTMonth;
  112.     static week_day BeginDSTDay;
  113.     static month    EndDSTMonth;
  114.     static week_day EndDSTDay;
  115.  
  116. protected:
  117.     zDate Set(month aMonth, int aDay, int aYear);
  118.     ulong MakeDayNumber() const;
  119.     void  FromDayNumber(ulong nDayNumber);
  120.  
  121. private:
  122.     month m_month;
  123.     int   m_day;
  124.     int   m_year;
  125.     ulong m_dayno;
  126. };
  127.  
  128. /*
  129.  * inline functions that belong to the zDate class
  130. */
  131.  
  132. inline int
  133. zDate::Year() const
  134. {
  135.     return m_year;
  136. }
  137.  
  138. inline int
  139. zDate::Day() const
  140. {
  141.     return m_day;
  142. }
  143.  
  144. inline zDate::month
  145. zDate::Month() const
  146. {
  147.     return m_month;
  148. }
  149.  
  150. inline ulong
  151. zDate::DayNumber() const
  152. {
  153.     return m_dayno;
  154. }
  155.  
  156. #endif /* __DATE_INC */
  157.